﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Topro.WCS
{
    using Topro.Service;
    using Topro.Util;

    /// <summary>
    /// 设置
    /// </summary>
    public partial class frmStation : Form
    {
        /// <summary>
        /// 站台
        /// </summary>
        public string stationId 
        { 
            get { 
                return this.dgStation.SelectedCells[0].Value.ToString(); 
            } 
        }

        public frmStation()
        {
            InitializeComponent();

            //样式
            dgStation.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;//列宽不自动调整,手工添加列
            //dgGateWay.RowHeadersWidth = 12;//行标题宽度固定12
            dgStation.RowHeadersWidthSizeMode = DataGridViewRowHeadersWidthSizeMode.DisableResizing;//不能用鼠标调整列标头宽度
            //dgGateWay.AlternatingRowsDefaultCellStyle.BackColor = Color.LemonChiffon;//奇数行背景色
            dgStation.BackgroundColor = Color.White;//控件背景色
            dgStation.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//列标题居中显示
            dgStation.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter;//单元格内容居中显示
            //行为
            dgStation.AutoGenerateColumns = false;//不自动创建列
            dgStation.AllowUserToAddRows = false;//不启用添加
            dgStation.ReadOnly = true;//不启用编辑
            dgStation.AllowUserToDeleteRows = false;//不启用删除
            dgStation.SelectionMode = DataGridViewSelectionMode.FullRowSelect;//单击单元格选中整行
            dgStation.MultiSelect = false;//不能多选
            dgStation.AllowUserToResizeRows = false;//禁止用户改变DataGridView1の所有行的行高
            dgStation.RowTemplate.Height = 100;//设置行高
            //dgGateWay.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;//自动填充
            dgStation.RowHeadersVisible = false;

            btncCnfirm.DialogResult = DialogResult.OK;
        }

        private void frmStation_Load(object sender, EventArgs e)
        {
            //获取指令列有
            string stockStationFilePath = $"{System.Environment.CurrentDirectory}\\TwoStockStation.xml";
            //获取xml内容
            var stockStationXml = FileUtil.loadFile(stockStationFilePath);
            //序列化
            var stockStations = SerializationUtil.XmlDeserialize<List<StockStation>>(stockStationXml);
            //
            this.dgStation.DataSource = new BindingList<StockStation>(stockStations.Distinct(c => c.Id).ToList());
        }

        /// <summary>
        /// 双击单元格
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void dgOutinStation_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            try
            {
                ////出入站台编号
                //int stationNo = 0;
                ////
                //MainForm mainForm = new MainForm();
                ////转换
                //int.TryParse(Convert.ToString(this.dgStation.CurrentRow.Cells[0].Value), out stationNo);
                //if(stationNo<=0)
                //{
                //    MessageBox.Show("请选择站台.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                //}
                //else
                //{

                //    //设置站台
                //    mainForm.Station(stationNo);
                //    //关闭
                //    this.Close();
                //}
            }
            catch (Exception ex)
            {
                
            }
        }
    }
}
